'Simple Digital Clock With 7-Segment
'Programmer: Majid Alinia (Savis_20@Yahoo.COM) MajidAlinia.Blogfa.COM
'Compiler : BASCOM 2.02.8.0
'Creation Date: May 02, 2011 (1390.02.12)
'Copyright: (C) 2011 By WWW.MajiAlinia.Blogfa.COM
'License: This Is A Free Firmware, Ver: 1.00 (Comm. Anode)
'---------------------------------------------------------------
$regfile = "m8def.dat"
$crystal = 1000000 'Internal RC
$hwstack = 64
$swstack = 64
$framesize = 64
'RTC
Config Clock = Soft , Gosub = Sectic
Enable Interrupts
Time$ = "12:00:00"
'I/O
Config Portd = Output 'A-G (Data)
Config Portc = Output
Config Pinb.0 = Input
Config Pinb.1 = Input
Config Pinb.2 = Output
'Set Pullup Resistor For Setting Key's
Set Portb.0
Set Portb.1
'Aliases
Dataport Alias Portd
Comm Alias Portc
Hour_key Alias Pinb.0
Min_key Alias Pinb.1
Second_led Alias Portb.2
'Variables
Dim Temp As Byte
Dim Temp2 As Byte
Dim Scnd As Byte
Dim Rtc_run As Byte
Dim S As Bit
Dim Dp As Bit
'Declaration
Declare Sub Keyscan
Declare Sub Refresh
Declare Sub Send
Declare Sub Wait4key
Declare Sub Blink_sec
'Wait 4 RTC Start
'Comm. Anode
'Hour Key
'Minute Key
'Blink Sec
Comm = &H0F 'Prompt
Do
If Rtc_run > 0 Then Exit Do
Loop
'Main Prog Start Here:
Do
Call Keyscan
Call Refresh
Call Blink_sec
Loop
End
Sub Keyscan
If Hour_key = 0 Then
Incr _hour
If _hour > 23 Then _hour = 0
Call Wait4key
End If
If Min_key = 0 Then
Incr _min
If _min > 59 Then _min = 0
Call Wait4key
End If
End Sub
Sub Refresh
Comm = &B1000 : Dp = 0 : Temp = _hour \ 10 : Call Send
Comm = &B0100 : Dp = 1 : Temp = _hour Mod 10 : Call Send
Comm = &B0010 : Dp = 0 : Temp = _min \ 10 : Call Send
Comm = &B0001 : Dp = 0 : Temp = _min Mod 10 : Call Send
End Sub
Sub Send
Dataport = Lookup(temp , Segdata)
If Dp = 1 Then
Portd.7 = S
Else
Portd.7 = 1
End If
Waitms 4
Dataport = &HFF
End Sub
Sub Wait4key
For Temp2 = 1 To 25
Call Refresh
Next
End Sub
Sub Blink_sec
Incr Scnd
If Scnd > 63 Then Scnd = 0
If Scnd > 0 And Scnd < 31 Then
S = 1
Else
S = 0
End If
End Sub
Segdata:
Data &B11000000 , &B11111001 , &B10100100 , &B10110000
Data &B10011001 , &B10010010 , &B10000010 , &B11111000
Data &B10000000 , &B10010000
Sectic:
Incr Rtc_run
Return